package com.css.common.core.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 税务机关相关类
 * @ClassName SwjgUtil
 * @Auther zhuowugong
 * @Date 2024/7/29 下午3:08
 */
@Slf4j
public class SwjgUtil {
	
	public static String ssjswjgDms[] = { "11100000000", "11200000000", "11300000000", "11400000000", "11500000000", "12100000000", "12102000000",
            "12200000000", "12300000000", "13100000000", "13200000000", "13300000000", "13302000000", "13400000000", "13500000000", "13502000000", 
            "13600000000", "13700000000", "13702000000", "14100000000", "14200000000", "14300000000", "14400000000", "14403000000", "14500000000", 
            "14600000000", "15000000000", "15100000000", "15200000000", "15300000000", "15400000000", "16100000000", "16200000000", "16300000000", 
            "16400000000", "16500000000"};

	public static String ssjxzqhDms[][] = { {"110000","北京市"}, {"120000","天津市"}, {"130000","河北省"}, {"140000","山西省"}, {"150000","内蒙古自治区"}, {"210000","辽宁省"}, {"220000","吉林省"},
			{"220000","吉林省"}, {"230000","黑龙江省"}, {"310000","上海市"}, {"320000","江苏省"}, {"330000","浙江省"}, {"340000","安徽省"}, {"350000","福建省"},
			{"360000","江西省"}, {"370000","山东省"}, {"410000","河南省"}, {"420000","湖北省"}, {"430000","湖南省"}, {"440000","广东省"}, {"450000","广西壮族自治区"},
			{"460000","海南省"}, {"500000","重庆市"}, {"510000","四川省"}, {"520000","贵州省"}, {"530000","云南省"}, {"540000","西藏自治区"}, {"610000","陕西省"}, {"620000","甘肃省"}, {"630000","青海省"},
			{"640000","宁夏回族自治区"}, {"650000","新疆维吾尔自治区"}};

	public static List<String> ssjswjgDmList = Arrays.asList(ssjswjgDms);
	
	public static String JRDWID = "174ba8fa83cf8ce25fa9";//"41a5ad2e1beaa76897ac";//接入单位乐企ID
	
	private static List<String> jhdlsSwjgs = Arrays.asList(new String[] { "14403", "13702", "13502", "13302", "12102" });
	
	/**
	 * 通过企业税号的3-6位获取省市级税务机关代码
	 */
	public static String getSsjswjgDmByQysh(String qysh) {
		if (GyUtils.isNull(qysh) || qysh.length()<6) {
			return null;
		}
		final String qysh_3 = qysh.substring(2, 6);
		String ssjswjgDm = "1"+qysh_3+"000000";
		if (!ssjswjgDmList.contains(ssjswjgDm))ssjswjgDm="1"+qysh.substring(2, 4)+"00000000";
		if (!ssjswjgDmList.contains(ssjswjgDm)) return null;
		return ssjswjgDm;
	}
	
	/**
	 * 通过机关获取省级机关
	 */
	public static String getSjSwjgDm(String swjgDm) {
	    if (StringUtils.isEmpty(swjgDm)) {
	       return swjgDm;
	    }
	    String head = swjgDm.substring(0, 5);
	    if (jhdlsSwjgs.contains(head)) {
	       return head + "000000";
	    }
	    return swjgDm.substring(0, 3) + "00000000";
   }
}
